#version 330 core
uniform sampler2D TextureBack;
uniform bool UseTexture;
//背景颜色
uniform vec4 BackColor;
//水颜色
uniform vec4 WaterColor;
//像素高
uniform float PixelHeight;
//偏移量(以周期为单位)
uniform float Offset;
//相位差
uniform float PasheDiffent;
//波浪密度（周期数量）
uniform float WaveDensity;
//浪高
uniform float WaveHeight;
//进度值
uniform float Value;

in vec2 TexCoords;
in vec2 Pos2D;
out vec4 FragColor;
void main(void)
{

    vec3 back=vec3(1.0);
    back=back*(1.-BackColor.a)+BackColor.rgb*BackColor.a;
    float sinx= (WaveDensity/2.)*Pos2D.x+Offset;
    sinx=radians(sinx*360.);
    float pashe=radians(PasheDiffent*360.);
    float siny1=sin(sinx)*WaveHeight+Value*2.-1.;
    float siny2=sin(sinx+pashe)*WaveHeight+Value*2.-1.;

    //float pixel10=20./PixelHeight;
    float pixel3=6./PixelHeight;
    float pixel1=2./PixelHeight;

    float alpha1=0.5;
    {
        //float smo1=pixel1+WaveHeight*abs(pixel10*cos(sinx));
        float smo1=pixel3+2.0*abs(pixel3*cos(sinx));
        smo1=smo1*WaveHeight+pixel1;
        float t1=Pos2D.y-siny1;
        alpha1=alpha1*(1.-smoothstep(0.,smo1,t1));
    }


    float alpha2=0.5;
    {
        //float smo2=pixel1+WaveHeight*abs(pixel10*cos(sinx+pashe));
        float smo2=pixel3+2.0*abs(pixel3*cos(sinx+pashe));
        smo2=smo2*WaveHeight+pixel1;
        float t2=Pos2D.y-siny2;
        alpha2=alpha2*(1.-smoothstep(0.,smo2,t2));
    }
    float alpha=(alpha1+alpha2)*WaterColor.a;
    FragColor=vec4(WaterColor.rgb*alpha+back*(1.-alpha),1.);
    //    vec3 back=vec3(1.0);
    //    back=back*(1-BackColor.a)+BackColor.rgb*BackColor.a;
    //    float sinx= (WaveDensity/2)*Pos2D.x+Offset;
    //    sinx=radians(sinx*360);
    //    float pashe=radians(PasheDiffent*360);
    //    float siny1=sin(sinx)*WaveHeight+Value*2-1;
    //    float siny2=sin(sinx+pashe)*WaveHeight+Value*2-1;

    //    float pixel10=20/PixelHeight;
    //    float pixel3=6/PixelHeight;
    //    float pixel1=2/PixelHeight;

    //    float alpha1=0.5;
    //    if(Pos2D.y>siny1)
    //    {
    //        float smo=pixel1+WaveHeight*abs(pixel10*cos(sinx));
    //        float t1=Pos2D.y-siny1;
    //        if(t1<smo)
    //        {
    //            float tt=smoothstep(smo,0,t1);
    //            alpha1=alpha1*tt;
    //        }
    //        else
    //            alpha1=0;
    //    }


    //    float alpha2=0.5;
    //    if(Pos2D.y>siny2)
    //    {
    //        float smo=pixel1+WaveHeight*abs(pixel10*cos(sinx+pashe));
    //        float t2=Pos2D.y-siny2;
    //        if(t2<smo)
    //        {
    //            float tt=smoothstep(smo,0,t2);
    //            alpha2=alpha2*tt;
    //        }
    //        else
    //            alpha2=0;
    //    }
    //    float alpha=(alpha1+alpha2)*WaterColor.a;
    //    FragColor=vec4(WaterColor.rgb*alpha+back*(1-alpha),1);


}
